import { response, errorHandle, url } from "./response";

const getToken = () => {
  return wx.getStorageSync("auth");
};

/**
 * 添加采集记录
 * @param {*} data
 * @param {*} successCallback
 */
export const add = (data, successCallback) => {
  wx.request({
    url: `${url}/collection_record/add`,
    method: "post",
    data,
    header: {
      "x-user-agent": "miniprogram",
      "x-auth-token": getToken(),
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    },
  });
};

/**
 * update记录
 * @param {*} data
 * @param {*} successCallback
 */
export const update = (data, successCallback) => {
  wx.request({
    url: `${url}/collection_record/update/relationId`,
    method: "post",
    data,
    header: {
      "x-user-agent": "miniprogram",
      "x-auth-token": getToken(),
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    },
  });
};
/**
 * update记录
 * @param {*} data
 * @param {*} successCallback
 */
export const _update = (data, successCallback) => {
  wx.request({
    url: `${url}/collection_record/update`,
    method: "post",
    data,
    header: {
      "x-user-agent": "miniprogram",
      "x-auth-token": getToken(),
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    },
  });
};
/**
 * update记录
 * @param {*} data
 * @param {*} successCallback
 */
export const updateStatus = (data, successCallback) => {
  wx.request({
    url: `${url}/collection_record/update/status`,
    method: "post",
    data,
    header: {
      "x-user-agent": "miniprogram",
      "x-auth-token": getToken(),
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    },
  });
};
/**
 * 采集记录
 * @param {*} data
 * @param {*} successCallback
 */
export const _get = (id, successCallback) => {
  wx.request({
    url: `${url}/collection_record/${id}`,
    method: "get",
    header: {
      "x-user-agent": "miniprogram",
      "x-auth-token": getToken(),
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    },
  });
};

/**
 * 删除单条记录
 * @param {*} data
 * @param {*} successCallback
 */
export const remove = (data, successCallback) => {
  wx.request({
    url: `${url}/collection_record/remove`,
    method: "post",
    data,
    header: {
      "x-user-agent": "miniprogram",
      "x-auth-token": getToken(),
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    },
  });
};

/**
 * 删除单条记录
 * @param {*} data
 * @param {*} successCallback
 */
export const remove_list = (data, successCallback) => {
  wx.request({
    url: `${url}/collection_record/remove/list`,
    method: "post",
    data,
    header: {
      "x-user-agent": "miniprogram",
      "x-auth-token": getToken(),
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    },
  });
};
